package com.xydtech.system.service.impl;

import com.xydtech.common.core.text.Convert;
import com.xydtech.common.utils.DateUtils;
import com.xydtech.system.domain.SysWechatApplet;
import com.xydtech.system.mapper.SysWechatAppletMapper;
import com.xydtech.system.service.ISysWechatAppletService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 微信小程序配置Service业务层处理
 *
 * @author JHON
 * @date 2021-10-12
 */
@Service
public class SysWechatAppletServiceImpl implements ISysWechatAppletService {
    @Autowired
    private SysWechatAppletMapper sysWechatAppletMapper;

    /**
     * 查询微信小程序配置
     *
     * @param id 微信小程序配置ID
     * @return 微信小程序配置
     */
    @Override
    public SysWechatApplet selectSysWechatAppletById(Long id) {
        return sysWechatAppletMapper.selectSysWechatAppletById(id);
    }

    /**
     * 查询微信小程序配置列表
     *
     * @param sysWechatApplet 微信小程序配置
     * @return 微信小程序配置
     */
    @Override
    public List<SysWechatApplet> selectSysWechatAppletList(SysWechatApplet sysWechatApplet) {
        return sysWechatAppletMapper.selectSysWechatAppletList(sysWechatApplet);
    }

    @Override
    public SysWechatApplet getWechatAppletByAppId(String appletType, String appid) {
        SysWechatApplet sysWechatApplet = new SysWechatApplet();
        sysWechatApplet.setAppid(appid);
        sysWechatApplet.setAppletType(appletType);
        List<SysWechatApplet> sysWechatAppletList = sysWechatAppletMapper.selectSysWechatAppletList(sysWechatApplet);
        if (sysWechatAppletList.size() > 0) {
            return sysWechatAppletList.get(0);
        }
        return null;
    }

    /**
     *查询微信小程序配置
     * @Title: getWechatAppletByAppId
     * @param appletType
     * @param deptId
     * @return com.xydtech.system.domain.SysWechatApplet
     * @exception
     * @author JHON
     * @Date 2021/10/12 10:09
     **/
    @Override
    public SysWechatApplet getWechatAppletByDeptId(String appletType, Long deptId) {
        SysWechatApplet sysWechatApplet = new SysWechatApplet();
        sysWechatApplet.setAppletType(appletType);
        sysWechatApplet.setDeptId(deptId);
        List<SysWechatApplet> sysWechatAppletList = sysWechatAppletMapper.selectSysWechatAppletList(sysWechatApplet);
        if (sysWechatAppletList.size() > 0) {
            return sysWechatAppletList.get(0);
        }
        return null;
    }

    /**
     * 新增微信小程序配置
     *
     * @param sysWechatApplet 微信小程序配置
     * @return 结果
     */
    @Override
    public int insertSysWechatApplet(SysWechatApplet sysWechatApplet) {
        sysWechatApplet.setCreateTime(DateUtils.getNowDate());
        return sysWechatAppletMapper.insertSysWechatApplet(sysWechatApplet);
    }

    /**
     * 修改微信小程序配置
     *
     * @param sysWechatApplet 微信小程序配置
     * @return 结果
     */
    @Override
    public int updateSysWechatApplet(SysWechatApplet sysWechatApplet) {
        return sysWechatAppletMapper.updateSysWechatApplet(sysWechatApplet);
    }

    /**
     * 删除微信小程序配置对象
     *
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    @Override
    public int deleteSysWechatAppletByIds(String ids) {
        return sysWechatAppletMapper.deleteSysWechatAppletByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除微信小程序配置信息
     *
     * @param id 微信小程序配置ID
     * @return 结果
     */
    @Override
    public int deleteSysWechatAppletById(Long id) {
        return sysWechatAppletMapper.deleteSysWechatAppletById(id);
    }
}
